package com.cy.springcloud.controller;

import com.cy.springcloud.service.PaymentService;
import com.cy.springcolud.entities.CommonResult;
import com.cy.springcolud.entities.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
public class PaymentController {

	@Autowired
	private PaymentService paymentService;

	@Value("${server.port}")
	private String serverPort;

	@GetMapping(value = "/payment/nacos/{id}")
	public String getPayment(@PathVariable("id") Integer id) {
		return "nacos registry, serverPort: " + serverPort + "\t id" + id;
	}

	@PostMapping("/payment/create")
	public CommonResult create(@RequestBody Payment payment){
		int result = paymentService.create(payment);
//        log.info("插入成功:"+result);
		if(result > 0){
			System.out.println(serverPort);
			return new CommonResult().success(result);
		}else {
			System.out.println(serverPort);
			return new CommonResult().fail(null);
		}
	}

	@GetMapping("/payment/get/{id}")
	public CommonResult getPaymentById(@PathVariable Long id){
		Payment payment = paymentService.getPaymentById(id);
//        log.info("查询成功:"+payment+"\t"+"哈哈");
		if(payment != null){
			System.out.println(serverPort);
			return new CommonResult().success(payment);
		}else {
			System.out.println(serverPort);
			return new CommonResult().fail(null);
		}
	}

}